<template>
  <card-layout title="年度治理情况" class="chart">
    <template #extra>
      <el-icon class="extra-more" :size="22">
        <Menu />
      </el-icon>
    </template>
    <div class="card-container">
      <div class="chart-container">
        <div class="pie-chart" ref="chartRef"></div>
        <div class="chart-label">
          <div class="percent">89.8%</div>
          <div class="txt">治理率</div>
        </div>
      </div>
      <div class="stat-group">
        <div class="item">
          <div class="value">56.32<span class="suffix">公顷</span></div>
          <div class="label">计划治理</div>
        </div>
        <div class="item">
          <div class="value">52.69<span class="suffix">公顷</span></div>
          <div class="label">累计治理</div>
        </div>
        <div class="item">
          <div class="value">12.13<span class="suffix">公顷</span></div>
          <div class="label">新增损毁</div>
        </div>
      </div>
    </div>
  </card-layout>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import useChart from "@/hooks/useCharts.js";
const chartRef = ref(null);
let { chartInstance } = useChart(chartRef);

// 初始化图表
const initChart = () => {
  const option = {
    tooltip: {
      show: false,
    },
    legend: {
      show: false,
    },
    series: [
      {
        name: "Access From",
        type: "pie",
        radius: ["65%", "90%"],
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: "center",
        },
        labelLine: {
          show: false,
        },
        data: [
          {
            value: 89.8,
            name: "已治理",
            itemStyle: {
              color: "#ffc107",
              borderRadius: "8px",
            },
          },
          {
            value: 10.2,
            name: "未治理",
            itemStyle: {
              color: "#9e9e9e9e",
              borderRadius: "8px",
            },
          },
        ],
      },
    ],
  };
  chartInstance.value.setOption(option);
};

onMounted(() => {
  initChart();
});
</script>

<style lang="scss" scoped>
.chart {
  box-sizing: border-box;
  flex: 0.6;

  .card-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 8px;
  }

  .chart-container {
    flex: 1;
    width: 100%;
    position: relative;

    .pie-chart {
      position: absolute;
      right: 0px;
      left: 0px;
      width: 100%;
      height: 100%
    }

    .chart-label {
      user-select: none;
      position: absolute;
      pointer-events: none;
      top: 0px;
      left: 0px;
      z-index: 1;
      height: 100%;
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      .percent {
        font-size: 24px;
        color: #fff;
      }

      .txt {
        color: #dedede;
        font-size: 14px;
      }
    }
  }

  .stat-group {
    margin-bottom: 8px;
  }

}
</style>
